import time
from common import add
from DB_CON import DB_con


# class testcase:
#     def __init__(self):
#         self.we = add.add()
#         self.we.login("admin","163415")
#     def case1(self,li):
#         newstepli=[]
#         stepli=li[4].split("\n")
#         for i in stepli:
#             newstepli.append(i.split("=")[1])
#         wd=self.we.add(newstepli)
#         result=self.jude(wd,li[-1])
#         if result:
#             print("case %s pass"%li[0])
#         else:
#             print("case %s failed"%li[0])
#
#     def jude(self,wd,exp):
#         result=True
#         try:
#             warn=wd.find_element_by_class_name("invalid-msg").text
#             if exp in warn:
#                 print("新增失败")
#             else:
#                 print("新增成功")
#             time.sleep(2)
#             with open("../TestReport/GUI测试报告.xls","a+") as f:        #把结果输出到表格中
#                 f.writelines(warn+"\n")
#
#         except:
#             str=DB_con.select_one("select name from tiny_goods where name")
#
#
#
#
#         return result
class testcase:
    def __init__(self):
        self.v = add.add()
        self.v.login("admin","123456")
    def case1(self,li):
        newli = []   #定义空列表
        l1 = li[4].split("\n")  #对表格的数据里面的"\n"进行分割
        for i in range(len(l1)):   #对分割后的列表进行遍历
            k = l1[i].split("=")  #对里面的每个值从“=”进行分割
            newli.append(k[1])  #对每个分割后的第二部分（也就是我们要的数据）依次增加到空列表中
        #现在列表中的每个下标所对应的数据就是我们对应要传的数据了
        wd = self.v.add(newli)
        a,b="",""
        time.sleep(2)

        try:
            a=wd.find_element_by_class_name("invalid-msg").text  #报错信息
            if a == '':
                a = "添加失败"
        except:
            b="添加成功"   #当不出现报错信息，默认为添加成功
        print(a,b)
        result = "" #定义一个结果
        if li[5] in a or li[5] in b :#从表格第六列结果进行判定
            result='%s--测试pass'%li[0]
            print(result)
        else:
            result='%s--测试failed'%li[0]
            print(result)
        with open("../TestReport/GUI测试报告.xls","a+") as f:
            f.writelines(result+"\n")


